<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/common/taglibs.jsp"%>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>系统管理</title>
<%@ include file="/common/util.jsp"%>


<script type="text/javascript">
var obj = {
	powerCodeVali : false,
	powerStandardValueVali : false,
	lightpowerTypeVali : false,
	addOrUpdate : function(){
		
		if("${editFlag}" == 0 ){
			obj.lightpowerTypeCheck();
			if(obj.powerCodeVali == false || obj.powerStandardValueVali == false || obj.lightpowerTypeVali ==false){
				dialog_alert("请正确填写表单！");
				return;
			}
			$("#addElecEnergyForm").attr("action", "${cdnctx}/systemElecEnergy/addElecEnergy.shtml");
			$("#addElecEnergyForm").submit(); 
		}else if("${editFlag}" == 1 ){
			obj.powerStandardValueCheck();
			if(obj.powerStandardValueVali == false){
				dialog_alert("请正确填写表单！");
				return;
			}
			var param = {"id":"${elecEnergyEntity.id}","modifyStamp":$("#modifyStamp").val()};
			$.ajax({
				type : "POST",
				contentType : "application/json",
				url : "versionElecEnergyVali.shtml",
				data : JSON.stringify(param),
				dataType : "json",
				success: function(data){
					if(data.versionFlag == true){
						$("#addElecEnergyForm").attr("action", "${cdnctx}/systemElecEnergy/updateElecEnergy.shtml");
						$("#addElecEnergyForm").submit(); 	
					}else{
						dialog_alert("这条数据已经被他人修改！");
					}
				},
				error: function(){
					dialog_alert("error");
				}
			});
		}else{
			dialog_alert("error");
		}
	},
	cancle : function(){
		var sumbitForm =  $("<form  method='post'></form>");
		sumbitForm.attr("action","${cdnctx}/systemElecEnergy/pageElecEnergyList.shtml");
        sumbitForm.append("<input type='hidden' name='elecEnergySearchEnity.powerCode' value='${elecEnergySearchEnity.powerCode}'>");
        sumbitForm.append("<input type='hidden' name='elecEnergySearchEnity.powerType' value='${elecEnergySearchEnity.powerType}'>");
        sumbitForm.append("<input type='hidden' name='pageIndex' value='${pageIndex}'>");
	    sumbitForm.appendTo(document.body).submit();
	},
	powerCodeCheck : function(){
		//验证格式
		var testStr = /^\+?[1-9][0-9]*$/;
		var powerCode = $("#powerCode").val();
		if(!testStr.test(powerCode)){
			$("#powerCodeError").html("请输入正整数！");
			$("#powerCodeError").css("display","block");
			obj.powerCodeVali = false;
			return;
		}else{
			$("#powerCodeError").css("display","none");
			obj.powerCodeVali = true;
		}
		
		$.ajax({
			type : "POST",
			contentType : "application/json",
			url : "powerCodeVali.shtml",
			data : powerCode,
			dataType : "json",
			success: function(data){
				if(data.existFlag == true){
					$("#powerCodeError").html("这个番号已被占用！");
					$("#powerCodeError").css("display","block");
					obj.powerCodeVali = false;
				}else{
					$("#powerCodeError").css("display","none");
					obj.powerCodeVali = true;
				}
			},
			error: function(){
				dialog_alert("error");
			}
		});
	},
	powerStandardValueCheck : function(){
		var testStr = /^\+?[1-9][0-9]*$/;
		var powerStandardValue = $("#powerStandardValue").val();
		if(!testStr.test(powerStandardValue)){
			$("#powerStandardValueError").html("请输入正整数！");
			$("#powerStandardValueError").css("display","block");
			obj.powerStandardValueVali = false;

		}else{
			$("#powerStandardValueError").css("display","none");
			obj.powerStandardValueVali =true;
		}
		
	},
	lightpowerTypeCheck :　function(){
		if("${editFlag}" == 1 ){
		return;
		}
		var params = {"lightType":$("#lightType").val(),"powerType":$("#powerType").val()};
		$.ajax({
			async:false,
			type : "POST",
			contentType : "application/json",
			url : "lightpowerTypeVali.shtml",
			data : JSON.stringify(params),
			dataType : "json",
			success: function(data){
				if(data.existFlag == true){
					$("#powerTypeError").html("灯具类型和能耗类型组合已经存在！");
					$("#powerTypeError").css("display","block");
					obj.lightpowerTypeVali = false;
				}else{
					$("#powerTypeError").css("display","none");
					obj.lightpowerTypeVali = true;
				}
			},
			error: function(){
				dialog_alert("error");
			}
		});
	}
};

$(document).ready(function(){
	if("${editFlag}" == 1 ){
		$("#powerCode").attr("disabled","disabled");
		$("#lightType").attr("disabled","disabled");
		$("#powerType").attr("disabled","disabled");
	}
	
	for ( var i = 1; i < 12; i++) {
        $("#id" + i).removeClass("current");
    }
    $("#id8").addClass("current");

});
</script>
</head>
<body class="main">
	<div class="-frame -style -luster" id="css_container">
		<!--首页框架页眉部分↓-->
		<%@ include file="/WEB-INF/pages/inc/header.jsp"%>
		<!--首页框架页眉部分↑-->

		<div class="content">

			<!-- Left导航菜单◎开始 -->
			<%@ include file="/WEB-INF/pages/inc/leftmenu.jsp"%>
			<!-- Left导航菜单◎结束 -->

			<div class="main-mid">
				<div class="pos"><img src="${cdnctx}/src/index/img/index.png"><a href="<%--${cdnctx}/system/systemMenu.shtml--%>">系统管理  ></a><a href="${cdnctx}/systemElecEnergy/elecEnergyList.shtml">度电能耗管理</a><a>> <c:if test="${empty elecEnergyEntity.id }">添加</c:if><c:if test="${not empty elecEnergyEntity.id }">编辑</c:if>度电能耗管理数据</a></div>
				<div class="css_contentDiv">
					<input type="hidden"  id="modifyStamp"  value="${elecEnergyEntity.modifyStamp}"/>
					<div class="searchDetailed  c-border-radius  b-box-shadow">
					<form id="addElecEnergyForm" method="post">
						  <input type="hidden"  id="searchPowerCode" name="elecEnergySearchEnity.powerCode" value="${elecEnergySearchEnity.powerCode}"/>
						  <input type="hidden"  id="searchPowerType" name="elecEnergySearchEnity.powerType" value="${elecEnergySearchEnity.powerType}"/>
						  <input type="hidden"  name="pageIndex" value="${pageIndex}"/>
						  <input type="hidden"  name="elecEnergyEntity.id" value="${elecEnergyEntity.id}"/>
						  <table align="center" width="600" border="0" cellspacing="0" cellpadding="0">
             				 <tr>
             				 	 <td width="91" height="36" class="mainText"><label class="formlabel"><font color="red">*</font>能耗番号：</label></td>
             				 	 <td width="205">
             				 	 <input type="text" class="form_input large" name="elecEnergyEntity.powerCode" id="powerCode" value="${elecEnergyEntity.powerCode}" maxlength="11"  onchange="obj.powerCodeCheck()"/>
			                      </td><td width="110" align="left">
			                      <div id="powerCodeError" style="display: none;color:red"></div>
             				 	 </td>
             				 </tr>
             				 
             				 <tr>
             				 	 <td width="91" height="36" class="mainText"> <label class="formlabel"><font color="red">*</font>灯具类型：</label></td>
             				 	 <td>
             				 	 <select id="lightType" name="elecEnergyEntity.lightType" onchange="obj.lightpowerTypeCheck()" class="form_select large">
			                      <option value="1" <c:if test="${1 == elecEnergyEntity.lightType}">selected</c:if>>传统灯具</option>
			                      <option value="2" <c:if test="${2 == elecEnergyEntity.lightType}">selected</c:if>>LED灯具</option>
			                  	 </select>
			                  	 </td><td width="110" align="left">
			                      <div id="powerTypeError" style="display: none;color:red"></div>
             				 	 </td>
             				 </tr>
             				 <tr>
             				 	 <td width="91" height="36" class="mainText"> <label class="formlabel"><font color="red">*</font>能耗类型：</label></td>
             				 	 <td>
             				 	 <select id="powerType" name="elecEnergyEntity.powerType" onchange="obj.lightpowerTypeCheck()" class="form_select large">
			                      <option value="1" <c:if test="${1 == elecEnergyEntity.powerType}">selected</c:if>>标准煤</option>
			                      <option value="2" <c:if test="${2 == elecEnergyEntity.powerType}">selected</c:if>>CO₂</option>
			                      <option value="3" <c:if test="${3 == elecEnergyEntity.powerType}">selected</c:if>>碳</option>
			                      <option value="4" <c:if test="${4 == elecEnergyEntity.powerType}">selected</c:if>>SO₂</option>
			                  	 </select>
             				 	 </td>
             				 </tr>
             				 
             				 <tr>
             				 	 <td width="91" height="36" class="mainText"><label class="formlabel"><font color="red">*</font>能耗标准：</label></td>
             				 	 <td>
             				 	 <input type="text" class="form_input large" name="elecEnergyEntity.powerStandardValue" id="powerStandardValue" value="${elecEnergyEntity.powerStandardValue}" maxlength="11"  onchange="obj.powerStandardValueCheck()"/>
			                      </td><td align="left">
			                      <div id="powerStandardValueError" style="display: none;color:red"></div>
             				 	 </td>
             				 </tr>
             				 <tr>
             				 	 <td width="91" height="36" class="mainText"> <label class="formlabel">备注：</label></td>
             				 	 <td>
                                 <textarea id="memo" name="elecEnergyEntity.memo" rows="4" cols="77" class="form_textarea large" >${elecEnergyEntity.memo}</textarea>
             				 	 </td>
             				 </tr>
             				 <tr>
             				 	<td height="20"></td>
             				 </tr>
             				 
             				 <tr >
             				 	<td ></td>
						         <td>
						               <input type="button" class="form_save" value="保&nbsp;存" onclick="obj.addOrUpdate()"/>
						               	
									   <input type="button" class="form_cancle" value="取&nbsp;消" onclick="obj.cancle()"/>
				              	</td>
             				 
             				 </tr>
             				</table>
              		</form>
              		</div>
				</div>
			</div>

		</div>

		<!--首页框架页尾部分↓-->
		<%@ include file="/WEB-INF/pages/inc/footer.jsp"%>
		<!--首页框架页尾部分↑-->
	</div>
</body>
</html>